﻿using System.Collections.Generic;

namespace PerceptiveMCAPI_Test
{
   public partial class sub_TemplateSections : System.Web.UI.UserControl
   {
      public bool ShowId { get; set; }
      //
      public Dictionary<string, string> TemplateSections
      {
         get { return getTemplateSections(); }
         set { setTemplateSections( value ); }
      }
      // ----------------------------
      public void Setup()
      {
         this.Visible = true;
         tbName01.Focus();
      }
      // ----------------------------------------------------
      private Dictionary<string, string> getTemplateSections()
      {
         Dictionary<string, string> ts = new Dictionary<string, string>();

         if ( tbName01.Text != "" )
            ts.Add(  tbName01.Text.Trim(), tbValue01.Text.Trim() );
         if ( tbName02.Text != "" )
            ts.Add(  tbName02.Text.Trim(), tbValue02.Text.Trim() );
         if ( tbName03.Text != "" )
            ts.Add(  tbName03.Text.Trim(), tbValue03.Text.Trim() );
         if ( tbName04.Text != "" )
            ts.Add(  tbName04.Text.Trim(), tbValue04.Text.Trim() );
         if ( tbName05.Text != "" )
            ts.Add(  tbName05.Text.Trim(), tbValue05.Text.Trim() );
         if ( tbName06.Text != "" )
            ts.Add(  tbName06.Text.Trim(), tbValue06.Text.Trim() );
         if ( tbName07.Text != "" )
            ts.Add(  tbName07.Text.Trim(), tbValue07.Text.Trim() );
         if ( tbName08.Text != "" )
            ts.Add(  tbName08.Text.Trim(), tbValue08.Text.Trim() );
         if ( tbName09.Text != "" )
            ts.Add(  tbName09.Text.Trim(), tbValue09.Text.Trim() );
         if ( tbName10.Text != "" )
            ts.Add(  tbName10.Text.Trim(), tbValue10.Text.Trim() );

         return ts;
      }

      private void setTemplateSections( Dictionary<string, string> value )
      {
         // pretty it up later
         clearTemplateSections();
         int i = 0;
         foreach ( KeyValuePair<string, string> kv in value )
         {
            i++;
            switch ( i )
            {
               case 1:
                  tbName01.Text = kv.Key;
                  tbValue01.Text = kv.Value;
                  break;
               case 2:
                  tbName02.Text = kv.Key;
                  tbValue02.Text = kv.Value;
                  break;
               case 3:
                  tbName03.Text = kv.Key;
                  tbValue03.Text = kv.Value;
                  break;
               case 4:
                  tbName04.Text = kv.Key;
                  tbValue04.Text = kv.Value;
                  break;
               case 5:
                  tbName05.Text = kv.Key;
                  tbValue05.Text = kv.Value;
                  break;
               case 6:
                  tbName06.Text = kv.Key;
                  tbValue06.Text = kv.Value;
                  break;
               case 7:
                  tbName07.Text = kv.Key;
                  tbValue07.Text = kv.Value;
                  break;
               case 8:
                  tbName08.Text = kv.Key;
                  tbValue08.Text = kv.Value;
                  break;
               case 9:
                  tbName09.Text = kv.Key;
                  tbValue09.Text = kv.Value;
                  break;
               case 10:
                  tbName10.Text = kv.Key;
                  tbValue10.Text = kv.Value;
                  break;
            }
         }
      }

      private void clearTemplateSections()
      {
         tbName01.Text = ""; tbValue01.Text = "";
         tbName02.Text = ""; tbValue02.Text = "";
         tbName03.Text = ""; tbValue03.Text = "";
         tbName04.Text = ""; tbValue04.Text = "";
         tbName05.Text = ""; tbValue05.Text = "";
         tbName06.Text = ""; tbValue06.Text = "";
         tbName07.Text = ""; tbValue07.Text = "";
         tbName08.Text = ""; tbValue08.Text = "";
         tbName09.Text = ""; tbValue09.Text = "";
         tbName10.Text = ""; tbValue10.Text = "";
      }
   }
}